const { pool, add, edit } = require('./baseModel.js')

exports.uploadPhoto = async (files) => {
    // console.log(files.user_photo.name);
    const fs = require('fs')
    let name = Date.now() + '_' + files.banner_img.name
    fs.writeFileSync(uploads + name, fs.readFileSync(files.banner_img.path))
    return '/uploads/' + name;
}

exports.add = async (fields) => {
    return await add('banner_info', fields)
}

exports.get = async () => {
    let time = parseInt(Date.now() / 1000)
    let result = await pool.query('select * from banner_info where start_time<? and end_time>? order by weight desc', [time, time])
    return result[0]
}